import { createRouter, createWebHashHistory } from 'vue-router'
import store from '@/store'

const routes = [
  {
    path:'/',
    name:'home',
    redirect:'/login'
  },
  {
    path:'/main',
    name:'main',
    component:()=>import('../views/Main.vue'),
    redirect:'/main/org/Department',
    children:[
      {
        path:'/main/org/Department',
        name:'department',
        component:()=>import('../views/org/DepartmentView.vue')
      },
      {
        path:'/main/org/Employee',
        name:'employee',
        component:()=>import('../views/org/EmployeeView.vue')
      },
      {
        path:'/main/system/Menu',
        name:'menu',
        component:()=>import('../views/system/MenuView.vue'),
      },
      {
        path:'/main/system/Permission',
        name:'permission',
        component:()=>import('../views/system/PermissionView.vue')
      },
      {
        path:'/main/system/Role',
        name:'role',
        component:()=>import('../views/system/RoleView.vue')
      },
      {
        path:'/main/regfee/AddRegister',
        name:'addRegister',
        component:()=>import('../views/regfee/AddRegisterView.vue')
      },
      {
        path:'/main/regfee/Register',
        name:'register',
        component:()=>import('../views/regfee/RegisterView.vue')
      },
      {
        path:'/main/regfee/Charge',
        name:'charge',
        component:()=>import('../views/regfee/ChargeView.vue')
      },
      {
        path:'/main/regfee/Refund',
        name:'refund',
        component:()=>import('../views/regfee/RefundView.vue')
      },
      {
        path:'/main/regfee/Record',
        name:'record',
        component:()=>import('../views/regfee/RecordView.vue')
      },
      {
				path: '/main/outpatient/Patient',
				name: 'patient',
				component: () => import('../views/outpatient/PatientView.vue'),
			},
			{
				path: '/main/outpatient/MedicalRecord/:rid/:realname',
				name: 'MedicalRecord',
				component: () => import('../views/outpatient/MedicalRecordView.vue'),
			},
      {
        path:'/main/check/Request',
        name:'Request',
        component:()=>import('../views/check/RequestView.vue')
      },
      {
				path: '/main/drugstore/SendDrug',
				name: 'SendDrug',
				component: () => import('../views/drugstore/SendDrugView.vue'),
			},
    ]
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/Login.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//路由守卫
router.beforeEach((to,from,next)=>{
    if(to.path != '/login'){
    let uname = localStorage.getItem('adminUser');
    if(!uname){
      if(from.path !='/login'){
        router.path = '/login';
      }
      return;
    }
  }
  next();
})
// router.beforeEach((to,from,next)=>{
//       console.log('路由守卫：',to.path);
//       store.state.elMenuActive = to.path;
//       next(); //放行
//   })

export default router
